package router

import (
	"github.com/gin-gonic/gin"
	"github.com/mattn/go-colorable"
	"web-service/api/controller"
)

func InitGinRouter() *gin.Engine {
	gin.ForceConsoleColor()
	gin.DefaultWriter = colorable.NewColorableStdout()
	ginRouter := gin.Default()
	//每个controller一个分组,结构比较清晰
	prodGroup := ginRouter.Group("/demo/v1/product")
	{
		ctrl := new(controller.ProductController)
		prodGroup.Handle("GET", "/list", ctrl.GetProductList)
		prodGroup.Handle("GET", "/detail", ctrl.GetProductDetail)
		prodGroup.Handle("POST", "/create", ctrl.CreateProduct)
		prodGroup.Handle("POST", "/update", ctrl.UpdateProduct)
		prodGroup.Handle("GET", "/delete", ctrl.DeleteProduct)
	}

	userGroup := ginRouter.Group("/demo/v1/user")
	{
		userCtrl := new(controller.UserController)
		userGroup.Handle("POST", "/login", userCtrl.Login)
		userGroup.Handle("POST", "/register", userCtrl.Register)
	}
	return ginRouter
}
